import numpy as np
import matplotlib.pyplot as plt


if __name__ == '__main__':
    history = np.load("res.npy",allow_pickle=True).item()
    print(type(history)) # <class 'dict'>

    loss = history["loss"]
    val_loss = history["val_loss"]
    dice_coef = history["dice_coefficient"]
    val_dice_coef = history["val_dice_coefficient"]

    # 画loss
    plt.plot(loss, label="train_loss")
    plt.plot(val_loss, label="val_loss")
    plt.xlabel("Epochs")
    plt.ylabel("Loss")
    plt.title("Train and Validation Losses Over Epochs", fontsize=14)
    plt.legend()
    plt.grid()
    plt.show()

    # 画dice_coef
    plt.plot(dice_coef, label="train_dice")
    plt.plot(val_dice_coef, label="val_dice")
    plt.xlabel("Epochs")
    plt.ylabel("dice_coef")
    plt.title("Train and Validation DiceCoef Over Epochs", fontsize=14)
    plt.legend()
    plt.grid()
    plt.show()
